import 'package:flame/components.dart';
import '../../entity/SpriteAnimationParamEntity.dart';
import '../../model/PlantModel.dart';
import '../HealthBar.dart';
import '../BodyShadow.dart';
import '../../../../component/SpriteAnimationEntity.dart';
import '../LawnCell.dart';

// 植物类
abstract class Plant extends SpriteAnimationEntity {
  final LawnCell cell; // 草坪
  double hp; // 生命值
  HealthBar? healthBar; // 血条
  late BodyShadow bodyShadow; // 阴影
  final PlantModel plantModel;

  Plant({
    required this.cell,
    required this.hp,
    required this.plantModel,
    required SpriteAnimationParamEntity initEntity,
  }) : super(
          initEntity,
          initPosition: cell.position + cell.size / 2,
        );

  @override
  Future<void> onLoad() async {
    priority = plantPriority;
    position = cell.position + cell.size / 2;
    anchor = Anchor.center;
    await super.onLoad();
    addHitBox(
      scaleHitBoxK: plantModel.scaleHitBoxK,
      hitBoxPosition: Vector2(
        plantModel.hitBoxKOffsetX,
        plantModel.hitBoxKOffsetY,
      ),
    ); // 添加碰撞
    healthBar = HealthBar(
      maxHealth: hp,
      currentHealth: hp,
      healthBarLeft: plantModel.healthBarLeft,
      healthBarTop: plantModel.healthBarTop,
    ); // 血条
    add(healthBar!);
  }
}
